﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApp1
{
    internal class Check
    {
        public static void Check_Ob(Plane plane, List<Obstacle> obstacles)
        {
            foreach (var obstacle in obstacles)
            {
                if (plane.GetRectangle().IntersectsWith(obstacle.GetRectangle()))
                {
                    plane.Life--; // 减少生命值
                    obstacles.Remove(obstacle); // 碰撞后移除障碍物
                    break;
                }
            }
        }

        public static void Check_Bul(List<Bullet> bullets, List<Obstacle> obstacles)
        {
            foreach (var bullet in bullets)
            {
                foreach (var obstacle in obstacles)
                {
                    if (bullet.GetRectangle().IntersectsWith(obstacle.GetRectangle()) )
                    {
                        obstacle.Boom(); // 障碍物受到伤害
                        bullet.IsAlive = false;
                        break;
                    }
                }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
            }
            obstacles.RemoveAll(o => o.IsDead);
            bullets.RemoveAll(b => !b.IsAlive);
        }
        

    }
}
